package com.example.administrator.liveapp.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.liveapp.ApplicationUtils;
import com.example.administrator.liveapp.MainActivity;
import com.example.administrator.liveapp.R;
import com.example.administrator.liveapp.utils.AppUrl;
import com.example.administrator.liveapp.utils.SharedPrefsUtil;
import com.example.administrator.liveapp.utils.TimeChangeUtil;
import com.github.yoojia.qrcode.qrcode.QRCodeEncoder;

/**
 * 以前活动门票activity(已经没有用了)
 */

public class SignUpSuccessPage extends AppCompatActivity {

    private ImageView Qr_code;
    private Button submit_button;
    private Bitmap qrCodeImage;
    private String activityId;//活动Id
    private String consumerId;//用户Id
    private String consumerName;//用户Name
    private SharedPrefsUtil sp;
    private TextView place;
    private String time;
    private String address;
    private TextView name;
    private TextView times;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sign_up_success_page);
        ApplicationUtils applicationUtils = new ApplicationUtils();
        applicationUtils.addActivity(this);
        initView();
        qrCodeImageView();

    }

    private void initView() {
        Intent intent = getIntent();
        sp = new SharedPrefsUtil();
        consumerId = intent.getStringExtra("consumerId");
        activityId = intent.getStringExtra("activityId");
        Qr_code = (ImageView) findViewById(R.id.Qr_code);
        submit_button = (Button) findViewById(R.id.submit_button);
        time = TimeChangeUtil.getStrTime(intent.getStringExtra("time"));
        address = intent.getStringExtra("address");
        name = (TextView) findViewById(R.id.consumerName);
        place = (TextView) findViewById(R.id.address);
        times = (TextView) findViewById(R.id.time);
        consumerName = ApplicationUtils.getInstance().loginBean.getConsumername();
        name.setText("\""+consumerName+"\"");
        place.setText(address);
        times.setText(time);
    }

    private void qrCodeImageView() {
        // 二维码中间图标
        final Bitmap centerImage = BitmapFactory.decodeResource(getResources(), R.mipmap.logo);
        // 生成的二维码图案
        qrCodeImage = new QRCodeEncoder.Builder()
                .width(180) // 二维码图案的宽度
                .height(180)
                .paddingPx(0) // 二维码的内边距
                .marginPt(0) // 二维码的外边距
                .centerImage(centerImage) // 二维码中间图标
                .build()
                .encode(AppUrl.URL+AppUrl.SignInURL+"?activityId="+activityId+"&consumerId="+consumerId+"&type=1");
        Qr_code.setImageBitmap(qrCodeImage);
        Qr_code.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        submit_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                final QRCodeDecoder mDecoder = new QRCodeDecoder.Builder().build();
//                // 传入二维码图案Bitmap对象然后解码成文本内容
//                String content = mDecoder.decode(qrCodeImage);
                Intent intent = new Intent();
                intent.putExtra("consumerId",consumerId);
                intent.setClass(SignUpSuccessPage.this,MainActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.zoomin,R.anim.zoomout);
            }
        });

    }
}
